package org.gangcai.mac.shop.adapter;

import android.content.Context;
import android.widget.ImageView;

import org.gangcai.mac.shop.R;
import org.gangcai.mac.shop.constants.Constant;
import org.gangcai.mac.shop.entity.MultipleItem;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import org.gangcai.mac.shop.entity.MultipleItem;

import java.util.List;

/**
 * https://github.com/CymChad/BaseRecyclerViewAdapterHelper
 * modify by AllenCoder
 */
public class MultipleItemQuickAdapter extends BaseMultiItemQuickAdapter<MultipleItem, BaseViewHolder> {
    private Context context;
    public MultipleItemQuickAdapter(Context context, List data) {
        super(data);
        this.context=context;
        addItemType(MultipleItem.TEXT, R.layout.item_text_view);
        addItemType(MultipleItem.IMG, R.layout.item_img_big_view);
        addItemType(MultipleItem.IMG_TEXT, R.layout.item_img_text_view);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultipleItem item) {
        switch (helper.getItemViewType()) {
            case MultipleItem.TEXT:
                helper.setText(R.id.tv, item.getContent());
                break;
            case MultipleItem.IMG:
                helper.setText(R.id.tv, item.getContent());
                if(this.context!=null){
                    Glide.with(this.context).load(Constant.IMAGE_PATHS + item.getThumb()).into((ImageView) helper.getView(R.id.iv));
                }
                helper.addOnClickListener(R.id.iv1);
                break;
            case MultipleItem.IMG_TEXT:
                helper.setText(R.id.tv, item.getContent());
                if(this.context!=null){
                    Glide.with(this.context).load(Constant.IMAGE_PATHS + item.getThumb()).into((ImageView) helper.getView(R.id.iv));
                }
                helper.addOnClickListener(R.id.iv1);
                break;
        }
    }

}
